package com.ckx.base;

import lombok.Data;
import org.slf4j.MDC;

@SuppressWarnings("unused")
@Data
public class CommonResult<T> {

    private int code;

    private String msg;

    private T data;

    private String traceId;

    public static <T> CommonResult<T> ok(T data) {
        CommonResult<T> result = new CommonResult<>();
        result.code = 0;
        result.msg = data.toString();
        result.traceId = MDC.get("requestId");
        return result;
    }

    public static <T> CommonResult<T> fail(int code, String msg) {
        CommonResult<T> result = new CommonResult<>();
        result.code = code;
        result.msg = msg;
        result.traceId = MDC.get("requestId");
        return result;
    }

}
